package com.mall.mapper;

import com.mall.pojo.OrderItem;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Options;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * 订单项Mapper接口
 */
@Mapper
public interface OrderItemMapper {
    
    /**
     * 插入订单项
     */
    @Insert("INSERT INTO order_item(order_id, sku_id, name, image, attrs_text, real_pay, quantity) " +
            "VALUES(#{orderId}, #{skuId}, #{name}, #{image}, #{attrsText}, #{realPay}, #{quantity})")
    @Options(useGeneratedKeys = true, keyProperty = "id")
    int insert(OrderItem orderItem);
    
    /**
     * 根据订单ID查询订单项列表
     */
    @Select("SELECT id, order_id AS orderId, sku_id AS skuId, name, image, attrs_text AS attrsText, real_pay AS realPay, quantity " +
            "FROM order_item WHERE order_id = #{orderId}")
    List<OrderItem> selectByOrderId(Long orderId);
} 